/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.polytec.beans;

import com.polytec.entities.Categorie;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Felix
 */
@Stateless
public class CategorieFacade extends AbstractFacade<Categorie> {
    @PersistenceContext(unitName = "our-projectPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public CategorieFacade() {
        super(Categorie.class);
    }
    
    
    public Categorie findByCategorieName(String categorieName) {
        // getEntityManager().createNamedQuery("Compte.findByLogin").setParameter("login", userName).getResultList().get(0);
        Categorie categorie;
        try {
            categorie = (Categorie) getEntityManager().createNamedQuery("Categorie.findByNomCategorie").setParameter("nomCategorie", categorieName).getSingleResult();
        } catch (NoResultException e) {
            return null;
        } catch (NonUniqueResultException e) {
            return null;
        }
        return categorie;
    }
    
}
